
import 'package:flutter/material.dart';
import 'package:flutter_ideal/page/page_home.dart';
import 'package:flutter_ideal/page/page_me.dart';
import 'package:flutter_ideal/widget/CircleProgressbar.dart';

class MainPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return new MainPageState();
  }

}
class MainPageState extends State<MainPage>{

  int _tabIndex = 0;
  var tabImages;
  var appBarTitles = ['会话', '联系人', '我'];
  /*
   * 存放三个页面，跟fragmentList一样
   */
  var _pageList;

  /*
   * 根据选择获得对应的normal或是press的icon
   */
  Image getTabIcon(int curIndex) {
    if (curIndex == _tabIndex) {
      return tabImages[curIndex][1];
    }
    return tabImages[curIndex][0];
  }
  /*
   * 获取bottomTab的颜色和文字
   */
  Text getTabTitle(int curIndex) {
    if (curIndex == _tabIndex) {
      return new Text(appBarTitles[curIndex],
          style: new TextStyle(fontSize: 14.0, color: const Color(0xff1296db)));
    } else {
      return new Text(appBarTitles[curIndex],
          style: new TextStyle(fontSize: 13.0, color: const Color(0xff515151)));
    }
  }
  /*
   * 根据image路径获取图片
   */
  Image getTabImage(path) {
    return new Image.asset(path, width: 24.0, height: 24.0);
  }
  @override
  Widget build(BuildContext context) {
    initData();
    return new Scaffold(appBar: new AppBar(),
    body: _pageList[_tabIndex],
      bottomNavigationBar: new BottomNavigationBar(items: <BottomNavigationBarItem>[

        new BottomNavigationBarItem(
            icon: getTabIcon(0), title: getTabTitle(0)),
        new BottomNavigationBarItem(
            icon: getTabIcon(1), title: getTabTitle(1)),
        new BottomNavigationBarItem(
            icon: getTabIcon(2), title: getTabTitle(2)),

      ], //点击事件
          onTap: (index) {
            setState(() {
              _tabIndex = index;
            });} ,),

    );
  }
  void initData() {
    /*
     * 初始化选中和未选中的icon
     */
    tabImages = [
      [getTabImage('images/icon_main_conversation_normal.png'), getTabImage('images/icon_main_conversation_click.png')],
      [getTabImage('images/icon_main_contact_normal.png'), getTabImage('images/icon_main_contact_click.png')],
      [getTabImage('images/icon_main_me_normal.png'), getTabImage('images/icon_main_me_click.png')]
    ];

    /*
     * 三个子界面
     */
    _pageList = [
      new HomePage(),
      new ProgressBarPage(),
      new PageMeState(),
    ];
  }

}